import Vue from 'vue'//引入vue
import Router from 'vue-router'//引入vue-router
import HelloWorld from '@/components/HelloWorld'
import Hi from "@/components/Hi";
import Hi1 from "@/components/Hi1";
import Hi2 from "@/components/Hi2";
import supplier from "@/components/supplier";
import supplierp from "../components/supplierp";
import client from "../components/client";
import business from "../components/business";
import left from "../components/left";
import right from "../components/right";
import params from "@/components/params";
import Error from "../components/Error";
//引入根目录下面的HelloWorld.vue组件

Vue.use(Router)//Vue全局使用Router

export default new Router({
  base: '/', // 加上这一行
  mode:'history',
  routes: [//配置路由,这里是一个数组
    {   //每一个链接都是一个对象
      path: '/', //链接路径
      name: 'HelloWorld',//路由名称
      components:{
        default:HelloWorld,
        left:left,
        right:right
      },
      beforeEnter:(to,from,next) => {
        console.log('我进入了params模板');
        console.log(to);
        console.log(from);
        //这边的next就相当于是一个开关,如果这个钩子函数中没有使用next()的胡话,页面就不能进行跳转了
        next(true);
      },
      alias: '/home'
    },{
      path: '/hi',
      name: 'Hi',
      component: Hi,
      children:[
        {path: 'Hi1',component: Hi1,name:'Hi1'},
        {path: 'Hi2',component: Hi2,name: 'Hi2'}
      ]
    },{
      path: '/supplier',
      name: 'supplier',
      component: supplier,
      alias : '/alias_supplier'
    },{
    path: '/supplierp',
      name: 'supplierp',
      component: supplierp
    },
    {
      path: '/client',
      name : 'client',
      component: client
    },{
    path: '/business',
      name: 'business',
      component: business
    },
    {
      //在传递id的时候必须是整数,在参数后面加上括号定义正则
      //加入了正则，我们在传递数组在外的其他参数,params.vue组件就不会接受到内容
      path: '/params/:newsId(\\d+)/:newsTitle',
      name: 'params',
      component: params
    },{
      path: '/goHome',
      redirect : '/'//重定向到指定的页面
    },
    {
      //带参数的路由传递
      path: '/goParams/:newsId(\\d+)/:newsTitle',
      redirect: '/params/:newsId(\\d+)/:newsTitle'
    },
    {
      path: '*',
      component: Error
    }
  ]
})

